﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Configuration;
using Utility;

namespace LiquidMeasure
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class SettingWindow : UserControl
    {
        public delegate void Finish();
        public event Finish onFinished;
        public SettingWindow()
        {
            InitializeComponent();
        }

        private void btnConfirm_Click(object sender, RoutedEventArgs e)
        {
            string sText = txtSampleCount.Text;
            int res;
            bool bok = int.TryParse(sText, out res);
            if(!bok)
            {
                txtSampleCount.Foreground = Brushes.Red;
                txtSampleCount.Text = "输入的样品数必须为数字！";
                return;
            }
            int maxCount = int.Parse(ConfigurationManager.AppSettings["MaxSampleCount"]);
            if (res <= 0 || res > maxCount)
            {
                txtInfo.Foreground = Brushes.Red;
                txtInfo.Text = string.Format("输入样品数必须在1-{0}之间！",maxCount);
                return;
            }
            GlobalVals.hasBuffy = (bool)chkHasBuffy.IsChecked;
            GlobalVals.totalSample = res;
            GlobalVals.samplesThisBatch = 10;
            if (GlobalVals.totalSample < GlobalVals.maxSamplesPerBatch * GlobalVals.curBatch)
                GlobalVals.samplesThisBatch = GlobalVals.totalSample % GlobalVals.maxSamplesPerBatch;

            this.Visibility = Visibility.Hidden;
            if( onFinished != null)
                onFinished();
        }

    

    }
       
   
}
